// 创建一个路由器
import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/components/Home.vue'
import About from '@/components/About.vue'
import News from '@/components/News.vue'
import Detail from '@/components/Detail.vue'

const router = createRouter({
    history: createWebHistory(), //工作模式
    routes: [
        {
            path: '/',
            redirect: '/home'
        },
        {
            name: 'zhuye',
            path: '/home',
            component: Home
        },
        {
            name: 'guanyu',
            path: '/about',
            component: About
        },
        {
            name: 'xinwen',
            path: '/news',
            component: News,
            children: [
                // {
                //     name: 'xiangqing',
                //     path: 'detail',
                //     component: Detail
                // }

                // {
                //     name: 'xiangqing',
                //     path: 'detail/:id/:title/:content?',
                //     component: Detail
                // }

                {
                    name: 'xiangqing',
                    path: 'detail/:id/:title/:content?',
                    component: Detail,
                    //只能适配params参数
                    props: true
                }
                // {
                //     name: 'xiangqing',
                //     path: 'detail',
                //     component: Detail,
                //     props(route){
                //         console.log(route)
                //         return route.query
                //     }
                // }
            ]
        }
    ]
})

export default router